<?php

namespace app\mobile\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Renwu extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
		$banner=Db::name('banner')->where([
			'type_data'=>1,
			'bannertype_id'=>8
		])->find();
		$this->assign('banner',$banner);

		$rs_type=Db::name('renwuzhuanlantype')->where(['show_switch'=>1])->order('weigh desc')->select();
		foreach($rs_type as $k=>$v){
			$rs_year=Db::name('renwuzhuanlan')
                ->where('renwuzhuanlantype_id',$v['id'])
                ->distinct(true)
                ->order('nianfen_date desc,updatetime desc,weigh desc')
                ->column('nianfen_date');

			foreach($rs_year as $m=>$n){

				$rs_type[$k]['year'][]=[
					'year_num'=>$n,
					'data'=>Db::name('renwuzhuanlan')->where([
						'nianfen_date'=>$n,
						'renwuzhuanlantype_id'=>$v['id'],
					])->order('nianfen_date desc,updatetime desc,weigh desc')->select(),
				];
			}


		}

		$this->assign('rs_type',$rs_type);

		$rs_year=Db::name('renwuzhuanlan')->distinct(true)->order('nianfen_date desc,updatetime desc,weigh desc')->column('nianfen_date');
		$all_type=[];
		foreach($rs_year as $k=>$v){
			$all_type[$k]['year']=$v;
			$all_type[$k]['data']=Db::name('renwuzhuanlan')->where([
				'nianfen_date'=>$v,
			])->order('nianfen_date desc,updatetime desc,weigh desc')->select();
		}
		$this->assign('rs_alltype',$all_type);

        return $this->view->fetch();
    }

	public function detail(Request $request){
		$id=$request->param('id/d',0);
		$rs=Db::name('renwuzhuanlan')->where(['id'=>$id])->find();

		if(is_null($rs)){
			$this->error('内容不存在');
		}
		Db::name('renwuzhuanlan')->where('id',$id)->setInc('views');
		$this->assign('rs',$rs);

		return $this->view->fetch();
	}

}
